home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows Expert
/
Windows Expert.iso
/
windownt
/
perlnt.zip
/
t
/
io
/
filetest.nt
< prev
next >
Wrap
Text File
|
1993-07-25
|
5KB
|
182 lines
#
# Test various file test operators.
# Also test file handle stuff that isn't tested elsewhere.
#
print "1..30\n";
$tfile = "test.tmp";
if (-e $tfile) {
chmod (0666, $tfile);
unlink $tfile;
}
open (T, ">$tfile") || die "can't open temp file\n";
print T "Test data\n";
close(T);
#
# Check that -r/-R and -w/-W do the same thing
#
# N.B. ownership tests are meaningless right now!
#
if (-w "$tfile") {print "ok 1\n";} else {print "not ok 1\n";}
if (-r "$tfile") {print "ok 2\n";} else {print "not ok 2\n";}
if (-o "$tfile") {print "ok 3\n";} else {print "not ok 3\n";}
if (-R "$tfile") {print "ok 4\n";} else {print "not ok 4\n";}
if (-W "$tfile") {print "ok 5\n";} else {print "not ok 5\n";}
if (-O "$tfile") {print "ok 6\n";} else {print "not ok 6\n";}
#
# make sure that -x works only on extension, not modes
#
chmod (0777, $tfile);
if (-x "$tfile") {print "not ok 7\n";} else {print "ok 7\n";}
if (-X "$tfile") {print "not ok 8\n";} else {print "ok 8\n";}
unlink "foo.exe" if -e "foo.exe";
open(T, ">foo.exe") || die "can't open foo.exe for writing\n";
print T "foo";
close(T);
#
# check various extension types
#
# N.B. NTFS has an execute permission. We'll need to insure that this
# is honored later.
#
if (-x "foo.exe") {print "ok 9\n";} else {print "not ok 9\n";}
rename ("foo.exe", "foo.cmd") || die "Can't rename foo.exe to foo.cmd\n";
if (-x "foo.cmd") {print "ok 10\n";} else {print "not ok 10\n";}
rename ("foo.cmd", "foo.bat") || die "Can't rename foo.cmd to foo.bat\n";
if (-x "foo.bat") {print "ok 11\n";} else {print "not ok 11\n";}
rename ("foo.bat", "foo.com") || die "Can't rename foo.bat to foo.com\n";
if (-x "foo.com") {print "ok 12\n";} else {print "not ok 12\n";}
unlink "foo.com";
#
# check that writability is affected when we turn off the write bits
#
chmod (0111, $tfile);
if (-w "$tfile") {print "not ok 13\n";} else {print "ok 13\n";}
if (-W "$tfile") {print "not ok 14\n";} else {print "ok 14\n";}
#
# Check that these don't work!
#
if (-S $tfile) {print "not ok 15\n";} else {print "ok 15\n";}
if (-l $tfile) {print "not ok 16\n";} else {print "ok 16\n";}
if (-p $tfile) {print "not ok 17\n";} else {print "ok 17\n";}
#
# Test Binary vs. Text test
#
if (-B $tfile) {print "not ok 18\n";} else {print "ok 18\n";}
if (-T $tfile) {print "ok 19\n";} else {print "not ok 19\n";}
chmod (0666, $tfile);
unlink $tfile;
open (T, ">$tfile") || die "Can't create $tfile\n";
binmode(T);
print T "\001\002\003\004\005\006\007\010\011\012\013";
close (T);
if (-B $tfile) {print "ok 20\n";} else {print "not ok 20\n";}
if (-T $tfile) {print "not ok 21\n";} else {print "ok 21\n";}
if (-e $tfile) {print "ok 22\n";} else {print "not ok 22\n";}
if (-s $tfile) {print "ok 23\n";} else {print "not ok 23\n";}
truncate($tfile, 10) || die "can't truncate $tfile to 10 bytes\n";
($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size) = stat($tfile);
if ($size == 10) {print "ok 24\n";} else {print "not ok 24\n";}
truncate($tfile, 0) || die "can't truncate $tfile to 0 bytes\n";
if (-z $tfile) {print "ok 25\n";} else {print "not ok 25\n";}
open (T, ">$tfile") || die "can't open $tfile\n";
print T "foo\n";
close(T);
if (-z $tfile) {print "not ok 26\n";} else {print "ok 26\n";}
if (-f $tfile) {print "ok 27\n";} else {print "not ok 27\n";}
unlink $tfile;
#
# check that -t works with STDIN being a file (i.e. returns false)
#
open (T, ">$tfile") || die "Can't open $tfile for writing\n";
print T 'if (-t) {print "not";} else {print "ok";}';
close T;
$x = `perl $tfile <$tfile`;
if ($x eq "ok") {print "ok 28\n";} else {print "not ok 28\n";}
unlink $tfile;
#
# check that the Here-is operator works
#
open (T, ">$tfile") || die "Can't open $tfile for writing: $!\n";
print T <<"HERE_IS_TEST";
This is a test of the here-is mechanism.
It was written to a file named $tfile
HERE_IS_TEST
close T;
open (T, $tfile) || die "Can't open $tfile for reading: $!\n";
@lines = <T>;
close T;
if (@lines == 2 &&
split(/ /, @lines[1]) &&
chop ($_[$#_]) &&
$_[$#_] eq $tfile) {
print ("ok 29\n");
}
else {
print "not ok 29\n";
}
#
# check that the data file handle works
#
@a = (1, 2, 3, 4, 5);
$ok = 1;
while (<DATA>) {
if ($a[0] == $_) {
shift(@a);
}
else {
$ok = 0;
last;
}
}
if ($ok) {print "ok 30\n";} else {print "not ok 30\n";}
#
# Don't delete the numbers after the end token! They're what
# the DATA file handle is reading!!!
#
__END__
1
2
3
4
5